package com.jy.api.service;

import com.jy.api.dao.EmployeeDao;
import com.jy.api.domain.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by hanxi on 2018/5/5.
 */
@Service
public class StaticsService {
    private JdbcTemplate jdbc;
    private EmployeeDao employeeDao;

    public List<Map<String, Object>> getEmployeeSalesStatics(short year, short month, String employeeId, String storeId) {
        Employee employee = employeeDao.findOne(employeeId);
        String sql = "select pt.`name` typeName,\n" +
                "       sum(f.amount) amount,\n" +
                "       sum(f.quantity) qty\n" +
                "  from d_date d,\n" +
                "       `f_daily_employee_kpi` f,\n" +
                "       `product_type` pt\n" +
                " where f.store_id= ? " +
                "  AND d.`day`= f.`bizdate`\n" +
                "   and f.`product_type_id`= pt.`id`\n" +
                "   and d.month= ?\n" +
                "   and f.employee_id= ?\n" +
                " group by pt.`id`, typeName\n" +
                " order by pt.`id` ";
        return jdbc.queryForList(sql,storeId, month, employee.getUsername());
    }

    @Autowired
    public void setJdbc(JdbcTemplate jdbc) {
        this.jdbc = jdbc;
    }

    @Autowired
    public void setEmployeeDao(EmployeeDao employeeDao) {
        this.employeeDao = employeeDao;
    }
}
